package org.linlinjava.litemall.admin.service;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.constant.ExcelXmlConstants;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.linlinjava.litemall.admin.beans.dto.LumiereLevelCouponDto;
import org.linlinjava.litemall.admin.beans.dto.LumierePayMemberDto;
import org.linlinjava.litemall.admin.beans.vo.*;
import org.linlinjava.litemall.admin.constant.LitemallAdminConstants;
import org.linlinjava.litemall.core.notify.AwsNotifyService;
import org.linlinjava.litemall.core.notify.NoticeHelper;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.beans.Constants;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestParam;

import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

import static org.linlinjava.litemall.admin.util.AdminResponseCode.MOBILE_CODE_ONE;

/**
 * 管理卢米埃支付会员服务
 *
 * @author yliyun
 * @date 2022/09/14
 */
@Component
public class AdminLumierePayMemberService {
    /**
     * 卢米埃支付会员服务
     */
    @Autowired
    private LumierePayMemberService lumierePayMemberService;

    /**
     * 卢米埃支付会员用户服务
     */
    @Autowired
    private LumierePayMemberUserService  lumierePayMemberUserService;

    /**
     * 卢米埃成员福利优惠服务
     */
    @Autowired
    private LumiereMemberWelfareCouponService lumiereMemberWelfareCouponService;

    /**
     * 卢米埃成员福利订阅服务
     */
    @Autowired
    private LumiereMemberWelfareSubscribeService lumiereMemberWelfareSubscribeService;

    /**
     * 卢米埃订阅规则服务
     */
    @Autowired
    private LumiereSubscribeRuleService lumiereSubscribeRuleService;

    /**
     * litemall店服务
     */
    @Autowired
    private LitemallShopService litemallShopService;

    /**
     * litemall地区服务
     */
    @Autowired
    private LitemallRegionService litemallRegionService;

    @Autowired
    private NoticeHelper noticeHelper;

    /**
     * aws通知服务
     */
    @Autowired
    private AwsNotifyService awsNotifyService;

    /**
     * litemall用户服务
     */
    @Autowired
    LitemallUserService litemallUserService;

    /**
     * litemall礼品卡服务
     */
    @Autowired
    private LitemallGiftCardService litemallGiftCardService;

    /**
     * 列表
     *
     * @param payMemberName 支付成员名
     * @param page          页面
     * @param limit         限制
     * @param sort          排序
     * @param order         订单
     * @return {@link Object}
     */
    public Object list(String payMemberName,String addTimeStartDate,String addTimeEndDate
                        ,Integer page, Integer limit,String sort,String order){

        LambdaQueryWrapper<LumierePayMember> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(payMemberName != null,LumierePayMember::getName,payMemberName);
        lambdaQueryWrapper.eq(LumierePayMember::getDeleted,false);

        // 添加时间范围查询条件
        if (!StringUtils.isEmpty(addTimeStartDate) && !StringUtils.isEmpty(addTimeEndDate)) {
            DateTimeFormatter timeDtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            lambdaQueryWrapper.between(LumierePayMember::getAddTime,LocalDate.parse(addTimeStartDate, timeDtf).atStartOfDay(), LocalDate.parse(addTimeEndDate, timeDtf).atTime(LocalTime.MAX));
        }
        lambdaQueryWrapper.orderByDesc(LumierePayMember::getAddTime);

        // 分页查询
        IPage<LumierePayMember> members = lumierePayMemberService.page(new Page<>(page, limit),lambdaQueryWrapper);

        // 构建返回结果
        List vos = members.getRecords().stream().map( member -> {
            LumierePayMemberVo vo = new LumierePayMemberVo();
            BeanUtils.copyProperties(member,vo);

            // 计算人数
            LumierePayMemberUserExample ex = new LumierePayMemberUserExample();
            //获得所有会员总人数
            Integer allUser =  lumierePayMemberUserService.countByMemberId(ex);
            //获得当前会员的拥有人数
            ex.or().andPayMemberIdEqualTo(member.getId());
            Integer count = lumierePayMemberUserService.countByMemberId(ex);

            //当前会员拥有的人数
            vo.setNumbers(count);

            //获得当前付费会员的所有用户，并过滤没有过期的用户且没有注销的用户
            int currentNumbers = lumierePayMemberUserService.list(Wrappers.lambdaQuery(LumierePayMemberUser.class)
                    .eq(LumierePayMemberUser::getPayMemberId, member.getId())
            ).stream()
                    .filter(payMemberUser ->
                            payMemberUser.getEndTime().isAfter(LocalDateTime.now())&& ObjectUtil.isNotNull(litemallUserService.getOne(Wrappers.lambdaQuery(LitemallUser.class).eq(LitemallUser::getId,payMemberUser.getUserId()).eq(LitemallUser::getDeleted,0))))
                    .collect(Collectors.toList()).size();
            //当前会员正在使用的人数  如果会员状态为停用则设置为0
            vo.setCurrentNumbers(member.getStatus().intValue()!=3?currentNumbers:0);
            // 计算 百分比
            // 设置保留几位小数， “.”后面几个零就保留几位小数，这里设置保留四位小数
            vo.setPer(vo.getCurrentNumbers() == 0?"0.00%":new DecimalFormat("0.00%").format(currentNumbers * 1.0 / count * 1.0));

            vo.setAddTime(member.getAddTime().toString());
            if(member.getShopIds() == null || member.getShopIds().length == 0){

                vo.setAreaLimit((byte)0);
            }else{
                vo.setAreaLimit((byte)1);
            }

            return vo;
        }).collect(Collectors.toList());
        members.setRecords(vos);
        return ResponseUtil.okPage(members);
    }

    /**
     * 新的支付成员列表查询方法，支持根据支付成员名、添加时间范围、排序字段和排序顺序进行查询。
     *
     * @param payMemberName    支付成员名
     * @param page             页码
     * @param limit            每页限制
     * @param sort             排序字段
     * @param order            排序顺序
     * @return 包含成员列表信息的响应对象
     */
    public Object listNew(String payMemberName, String startTimeStartDate,String startTimeEndDate, String endTimeStartDate, String endTimeEndDate, Integer page, Integer limit, String sort, String order) {
        // 构建查询条件
        LambdaQueryWrapper<LumierePayMember>  lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(payMemberName != null,LumierePayMember::getName,payMemberName);
        lambdaQueryWrapper.eq(LumierePayMember::getDeleted,false);

        if (!StringUtils.isEmpty(startTimeStartDate) && !StringUtils.isEmpty(startTimeEndDate)) {
            DateTimeFormatter timeDtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            lambdaQueryWrapper.between(LumierePayMember::getAddTime,
                    LocalDate.parse(startTimeStartDate, timeDtf).atStartOfDay(),
                    LocalDate.parse(startTimeEndDate, timeDtf).atTime(LocalTime.MAX)
            );
        }
        if (!StringUtils.isEmpty(endTimeStartDate) && !StringUtils.isEmpty(endTimeEndDate)) {
            DateTimeFormatter timeDtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            lambdaQueryWrapper.between(LumierePayMember::getAddTime,
                    LocalDate.parse(endTimeStartDate, timeDtf).atStartOfDay(),
                    LocalDate.parse(endTimeEndDate, timeDtf).atTime(LocalTime.MAX)
            );
        }
        lambdaQueryWrapper.orderByDesc(LumierePayMember::getAddTime);
        IPage<LumierePayMember> members = lumierePayMemberService.page(new Page<>(page, limit),lambdaQueryWrapper);
        // 构建响应对象
        List vos = members.getRecords().stream().map(this::buildVo).collect(Collectors.toList());
        members.setRecords(vos);
        return ResponseUtil.okPage(members);
    }

    /**
     * 构建支付成员VO对象
     *
     * @param member 支付成员实体对象
     * @return 支付成员VO对象
     */
    private LumierePayMemberVo buildVo(LumierePayMember member) {
        LumierePayMemberVo vo = new LumierePayMemberVo();
        BeanUtils.copyProperties(member, vo);

        LumierePayMemberUserExample ex = new LumierePayMemberUserExample();
        ex.or().andPayMemberIdEqualTo(member.getId());
        Integer count = lumierePayMemberUserService.countByMemberId(ex);
        vo.setNumbers(count);

        int currentNumbers = lumierePayMemberUserService.list(Wrappers.lambdaQuery(LumierePayMemberUser.class)
                        .eq(LumierePayMemberUser::getPayMemberId, member.getId())
                ).stream()
                .filter(payMemberUser -> payMemberUser.getEndTime().isAfter(LocalDateTime.now()) &&
                        ObjectUtil.isNotNull(litemallUserService.getOne(Wrappers.lambdaQuery(LitemallUser.class)
                                .eq(LitemallUser::getId, payMemberUser.getUserId())
                                .eq(LitemallUser::getDeleted, 0))))
                .collect(Collectors.toList()).size();
        vo.setCurrentNumbers(member.getStatus().intValue() != 3 ? currentNumbers : 0);

        vo.setPer(vo.getCurrentNumbers() == 0 ? "0.00%" : new DecimalFormat("0.00%").format(currentNumbers * 1.0 / count * 1.0));
        vo.setAddTime(member.getAddTime().toString());
        vo.setAreaLimit((member.getShopIds() == null || member.getShopIds().length == 0) ? (byte) 0 : (byte) 1);
        return vo;
    }



    /**
     * 更新状态
     *
     * @param memberId 成员身份
     * @return {@link Object}
     */
    public Object updateStatus(Integer memberId){
        /*新需求 - 付费会员-不管还有没有人订阅 都可以下架 下架后 已经订阅了的客户一直用到过期
        List<LumierePayMemberUser> users = listUserByPayMember(memberId);
        if(users.size() > 0){
            return ResponseUtil.fail(111,"已有用户拥有该付费会员,不能修改状态");
        }*/

        LumierePayMember member  =  lumierePayMemberService.findById(memberId);

        if(member == null || member.getDeleted() == true){
            return ResponseUtil.fail(111,"付费会员不存在,不能修改状态");
        }


        if(member.getStatus() == Constants.MEMBER_STATUS_ADD){
            member.setStatus(Constants.MEMBER_STATUS_INUSE);
            member.setEndTime(LocalDateTime.now());
            member.setStartTime(null);
        }else if(member.getStatus() == Constants.MEMBER_STATUS_INUSE){
            member.setStatus(Constants.MEMBER_STATUS_NOUSE);
            member.setEndTime(LocalDateTime.now());
            member.setStartTime(null);
        }else if(member.getStatus() == Constants.MEMBER_STATUS_NOUSE){
            member.setStatus(Constants.MEMBER_STATUS_INUSE);
            member.setStartTime(LocalDateTime.now());
            member.setEndTime(null);
        }
        if(member.getStatus()==2&&member.getEndTime()!=null&&member.getEndTime().isBefore(LocalDateTime.now())){
            return ResponseUtil.fail(4000,"会员设置有效期已过");
        }
        lumierePayMemberService.update(member);
        if(member.getStatus()!=3){return ResponseUtil.ok("更新付费会员状态成功");}

        //推送订阅下架 系统消息
        List<LumierePayMemberUser> lumierePayMemberUsers = lumierePayMemberUserService.list(Wrappers.lambdaQuery(LumierePayMemberUser.class)
                .eq(LumierePayMemberUser::getPayMemberId, member.getId()));

        List<Integer> collect = lumierePayMemberUsers.stream().map(LumierePayMemberUser::getUserId).distinct().collect(Collectors.toList());
        CompletableFuture.runAsync(()->{
            collect.stream().forEach(userId->{
                if(userId==null){return;}
                LitemallUser litemallUser = litemallUserService.findById(userId);
                //系统消息
                noticeHelper.noticeUser(Constants.MSG_TYPE_PROMOTION, LitemallAdminConstants.ADMIN_MEMBERSHIP_TITLE,
                        String.format(LitemallAdminConstants.ADMIN_MEMBERSHIP_USER_NOTICEHELPER,member.getName()),userId,member);
                //短信消息
                if(StrUtil.isNotBlank(litemallUser.getMobile())){
                    awsNotifyService.sendSms(MOBILE_CODE_ONE +litemallUser.getMobile(),
                            String.format(LitemallAdminConstants.ADMIN_MEMBERSHIP_USER_NOTICEHELPER,member.getName()),
                            Constants.AWS_MESSAGE_TYPE_PROMOTIONAL);
                }
                //邮箱消息
                if(StrUtil.isNotBlank(litemallUser.getEmail())){
                    awsNotifyService.noticeMail(LitemallAdminConstants.ADMIN_MEMBERSHIP_TITLE,
                            String.format(LitemallAdminConstants.ADMIN_MEMBERSHIP_USER_NOTICEHELPER,member.getName()),
                            String.format(LitemallAdminConstants.ADMIN_MEMBERSHIP_USER_NOTICEHELPER,member.getName()),
                            litemallUser.getEmail());
                }
            });
        });
        return ResponseUtil.ok("更新付费会员状态成功");
    }

    /**
     * 删除
     *
     * @param memberId 成员身份
     * @return {@link Object}
     */
    public Object delete(Integer memberId){
        List<LumierePayMemberUser> users = listUserByPayMember(memberId);

        if(users.size() > 0){
            return ResponseUtil.fail(111,"已有用户拥有该付费会员,不能删除");
        }

        lumierePayMemberService.delete(memberId);
        return ResponseUtil.ok("删除付费会员成功");
    }

    /**
     * TODO 添加 付费会员
     *
     * @param dto dto
     * @return {@link Object}
     */
    @Transactional
    public Object add(LumierePayMemberDto dto){
        LumierePayMember member = new LumierePayMember();

        if(lumierePayMemberService.findByName(dto.getName()).size() > 0){
            return ResponseUtil.fail(111,"该会员名称已存在");
        }


        /** TODO 需异步优化 */
        //优惠券
        List<LumiereLevelCouponDto> coupons = dto.getCouponDtos();

        List<LumiereMemberWelfareCoupon> welfareCoupons = new ArrayList<>();
        if(coupons != null && coupons.size() > 0){
            coupons.stream().forEach(coupon -> {
                LumiereMemberWelfareCoupon welfareCoupon = new LumiereMemberWelfareCoupon();
                BeanUtils.copyProperties(coupon,welfareCoupon);
                welfareCoupon.setMemberTypes((byte)2);
                welfareCoupon.setNumbers(coupon.getNumber());
                welfareCoupon.setAddTime(LocalDateTime.now());
                welfareCoupon.setUpdateTime(LocalDateTime.now());
                welfareCoupon.setDeleted(false);
                welfareCoupons.add(welfareCoupon);
            });
        }

        //订阅
        List<MemberSubscribeVo> subscribeVos = dto.getSubscribeVos();
        List<LumiereMemberWelfareSubscribe> welfareSubscribes = new ArrayList<>();

        if(subscribeVos != null && subscribeVos.size() >0){
            for (int i = 0; i < subscribeVos.size(); i++) {
                Integer[]  ruleIds = subscribeVos.get(i).getSubscribeRuleIds();
                for (int j = 0; j < ruleIds.length; j++) {
                    LumiereSubscribeRule rule = lumiereSubscribeRuleService.queryBySubscibeAndRuleId(subscribeVos.get(i).getSubscribeId(),ruleIds[j]);

                    if (rule == null) {
                        return ResponseUtil.fail(111, "订阅规则不存在");
                    }
                }

                LumiereMemberWelfareSubscribe welfareSubscribe = new LumiereMemberWelfareSubscribe();
                welfareSubscribe.setMemberTypes((byte) 2);
                welfareSubscribe.setSubscribeRuleIds(ruleIds);
                welfareSubscribe.setSubscribeId(subscribeVos.get(i).getSubscribeId());
                welfareSubscribe.setAddTime(LocalDateTime.now());
                welfareSubscribe.setUpdateTime(LocalDateTime.now());
                welfareSubscribe.setDeleted(false);
                welfareSubscribes.add(welfareSubscribe);
            }
        }

        BeanUtils.copyProperties(dto,member);
        //礼物卡
        if(dto.getGiftCardVos() != null && dto.getGiftCardVos().size() > 0){
            Integer[] giftCardIds = new Integer[dto.getGiftCardVos().size()];
            for (int i = 0; i < dto.getGiftCardVos().size(); i++) {
                giftCardIds[i] = dto.getGiftCardVos().get(i).getGiftCardId();
            }
            member.setGiftCardIds(giftCardIds);
        }else{
            Integer[] arr = new Integer[0];
            member.setGiftCardIds(arr);
        }


        //新增等级会员
        member.setAddTime(LocalDateTime.now());
        member.setUpdateTime(LocalDateTime.now());
        member.setDeleted(false);
        member.setStatus((byte)1);
        member.setIsOverlay(dto.getIsOverlay());
        member.setStartTime(dto.getStartTime());
        member.setEndTime(dto.getEndTime());
//        member.setDiscountPer(dto.getDicountPer());
        //添加
        lumierePayMemberService.add(member);

        welfareCoupons.stream().forEach(coupon -> {
            coupon.setMemberId(member.getId());
            lumiereMemberWelfareCouponService.add(coupon);

        });

        welfareSubscribes.stream().forEach(subscribe -> {
            subscribe.setMemberId(member.getId());
            lumiereMemberWelfareSubscribeService.add(subscribe);
        });

        return ResponseUtil.ok("添加付费会员成功");
    }

    /**
     * 更新
     *
     * @param dto dto
     * @return {@link Object}
     */
    public Object update(LumierePayMemberDto dto){

        if(dto.getId() == null){
            return ResponseUtil.fail(222,"付费会员Id不能为空");
        }

        List<LumierePayMemberUser> users = listUserByPayMember(dto.getId());

//        if(users.size() > 0){
//            return ResponseUtil.fail(111,"已有用户拥有该付费会员,不能编辑");
//        }

        LumierePayMember member = lumierePayMemberService.findById(dto.getId());

        //优惠券
        List<LumiereLevelCouponDto> coupons = dto.getCouponDtos();

        List<LumiereMemberWelfareCoupon> welfareCoupons = new ArrayList<>();
        if(coupons != null && coupons.size() > 0){
            coupons.stream().forEach(coupon -> {
                LumiereMemberWelfareCoupon welfareCoupon = new LumiereMemberWelfareCoupon();
                BeanUtils.copyProperties(coupon,welfareCoupon);
                welfareCoupon.setMemberTypes((byte)2);
                welfareCoupon.setNumbers(coupon.getNumber());
                welfareCoupon.setAddTime(LocalDateTime.now());
                welfareCoupon.setUpdateTime(LocalDateTime.now());
                welfareCoupon.setDeleted(false);
                welfareCoupons.add(welfareCoupon);
            });
        }

        //订阅
        List<MemberSubscribeVo> subscribeVos = dto.getSubscribeVos();
        List<LumiereMemberWelfareSubscribe> welfareSubscribes = new ArrayList<>();

        if(subscribeVos != null && subscribeVos.size() >0){
            for (int i = 0; i < subscribeVos.size(); i++) {
                Integer[]  ruleIds = subscribeVos.get(i).getSubscribeRuleIds();
                for (int j = 0; j < ruleIds.length; j++) {
                    LumiereSubscribeRule rule = lumiereSubscribeRuleService.queryBySubscibeAndRuleId(subscribeVos.get(i).getSubscribeId(),ruleIds[j]);

                    if (rule == null) {
                        return ResponseUtil.fail(111, "订阅规则不存在");
                    }
                }

                LumiereMemberWelfareSubscribe welfareSubscribe = new LumiereMemberWelfareSubscribe();
                welfareSubscribe.setMemberTypes((byte) 2);
                welfareSubscribe.setSubscribeRuleIds(ruleIds);
                welfareSubscribe.setSubscribeId(subscribeVos.get(i).getSubscribeId());
                welfareSubscribe.setAddTime(LocalDateTime.now());
                welfareSubscribe.setUpdateTime(LocalDateTime.now());
                welfareSubscribe.setDeleted(false);
                welfareSubscribes.add(welfareSubscribe);
            }
        }


        //修改等级会员

        BeanUtils.copyProperties(dto,member);
        //礼物卡
        if(dto.getGiftCardVos() != null && dto.getGiftCardVos().size() > 0){
            Integer[] giftCardIds = new Integer[dto.getGiftCardVos().size()];
            for (int i = 0; i < dto.getGiftCardVos().size(); i++) {
                giftCardIds[i] = dto.getGiftCardVos().get(i).getGiftCardId();
            }
            member.setGiftCardIds(giftCardIds);
        }else{
            Integer[] arr = new Integer[0];
            member.setGiftCardIds(arr);
        }
//        member.setDiscountPer(dto.getDicountPer());
        lumierePayMemberService.update(member);

        //删除优惠券相关
        LumiereMemberWelfareCouponExample example = new LumiereMemberWelfareCouponExample();
        example.or().andMemberIdEqualTo(dto.getId());
        lumiereMemberWelfareCouponService.deleteByExample(example);

        welfareCoupons.stream().forEach(coupon -> {
            coupon.setMemberId(member.getId());
            lumiereMemberWelfareCouponService.add(coupon);

        });

        //删除订阅相关
        LumiereMemberWelfareSubscribeExample ex = new LumiereMemberWelfareSubscribeExample();
        ex.or().andMemberIdEqualTo(dto.getId());
        lumiereMemberWelfareSubscribeService.deleteByExample(ex);

        welfareSubscribes.stream().forEach(subscribe -> {
            subscribe.setMemberId(member.getId());
            lumiereMemberWelfareSubscribeService.add(subscribe);
        });

        return ResponseUtil.ok("修改付费会员成功");
    }

    /**
     * 细节
     *
     * @param memberId 成员身份
     * @return {@link Object}
     */
    public Object detail(Integer memberId){
        LumierePayMember payMember = lumierePayMemberService.findById(memberId);
        PayMemberVo vo = new PayMemberVo();
        BeanUtils.copyProperties(payMember,vo);
        //查询优惠券
        List<LumiereMemberWelfareCoupon> coupons =  lumiereMemberWelfareCouponService.findByMemberId(memberId,(byte)2);
        List<LumiereLevelCouponDto> couponDtos = new ArrayList<>();
        for (LumiereMemberWelfareCoupon memberWelfareCoupon:coupons) {
            LumiereLevelCouponDto couponDto = new LumiereLevelCouponDto();
            couponDto.setCouponId(memberWelfareCoupon.getCouponId());
            couponDto.setCycleType(memberWelfareCoupon.getCycleType());
            couponDto.setNumber(memberWelfareCoupon.getNumbers());
            couponDtos.add(couponDto);
        }
        vo.setCouponDtos(couponDtos);

        //订阅
        List<LumiereMemberWelfareSubscribe> welfareSubscribes =  lumiereMemberWelfareSubscribeService.findByMemberId(memberId,(byte)2);

        List<MemberSubscribeVo> subscribeVos  = welfareSubscribes.stream().map( subscribe -> {
            MemberSubscribeVo v = new MemberSubscribeVo();
            v.setSubscribeId(subscribe.getSubscribeId());
            v.setSubscribeRuleIds(subscribe.getSubscribeRuleIds());
            return v;
        }).collect(Collectors.toList());

        vo.setSubscribeVos(subscribeVos);

        List<MemberGiftCardVo> giftCardVos = new ArrayList<>();
       if(payMember.getGiftCardIds() != null && payMember.getGiftCardIds().length > 0){
           for (int i = 0; i < payMember.getGiftCardIds().length; i++) {
               MemberGiftCardVo v = new MemberGiftCardVo();
               LitemallGiftCard giftCard = litemallGiftCardService.findById(payMember.getGiftCardIds()[i]);

               if(giftCard != null){
                   v.setGiftCardName(giftCard.getName());
               }
               v.setGiftCardId(payMember.getGiftCardIds()[i]);
               giftCardVos.add(v);
           }
       }
        vo.setGiftCardVos(giftCardVos);
        return ResponseUtil.ok(vo);
    }

    /**
     * 用户通过支付成员列表
     *
     * @param memberId 成员身份
     * @return {@link List}<{@link LumierePayMemberUser}>
     */
    public List<LumierePayMemberUser> listUserByPayMember(Integer memberId){
        LumierePayMemberUserExample example = new LumierePayMemberUserExample();
        example.or().andPayMemberIdEqualTo(memberId);
        return lumierePayMemberUserService.list(example);
    }
}
